package sdk.webview.fmc.com.fmcsdk.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;


import sdk.webview.fmc.com.fmcsdk.R;
import sdk.webview.fmc.com.fmcsdk.activity.LoginActivity;
import sdk.webview.fmc.com.fmcsdk.interfaces.OnDialogSureListener;
import sdk.webview.fmc.com.fmcsdk.util.DialogUtils;
import sdk.webview.fmc.com.fmcsdk.util.Utility;
import sdk.webview.fmc.com.fmcsdk.view.ErrorDialog;


public class CenterCommDialog extends Dialog {
    private Context context;
    /**标题和内容*/
    private String msg,tips;

    private TextView confirm;
    private TextView tv_message;
    private boolean isLogin;
    private OnDialogSureListener onDialogSureListener;

    //只有提示内容的消息框
    public CenterCommDialog(Context context, String tips, String msg, boolean isLogin, OnDialogSureListener onDialogSureListener) {
        super(context, R.style.Dialog);
        this.context = context;
        this.msg = msg;
        this.tips = tips;
        this.isLogin=isLogin;
        this.onDialogSureListener=onDialogSureListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.error_dialog_tip);
        confirm = (TextView) findViewById(R.id.confirm);
        tv_message = (TextView) findViewById(R.id.tv_message);
        tv_message.setText(tips);
        confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(isLogin){
                    onDialogSureListener.onDialogSureListener();
                }else{
                    context.startActivity(new Intent(context,LoginActivity.class));
                    Utility.startLoginActivityOrClearData(context);
                }
                dismiss();
            }
        });
        //试着提示框的位置和大小
        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高
        lp.width = (int) (d.widthPixels * 0.9);
        dialogWindow.setAttributes(lp);

    }

    public void setConfirmText(String text){
        confirm.setText(text);
    }

    @Override
    public void dismiss() {
        super.dismiss();
        DialogUtils.dialogSSL=false;
    }
}



